package com.lx.request;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/demo1")
public class RequestDemo1 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       //获取请求头数据
        String agent = req.getHeader("user-agent");
        System.out.println(agent);
        //1.获取请求方式
        String method = req.getMethod();
        System.out.println(method);
        //2.获取虚拟目录
        String ContextPath = req.getContextPath();
        System.out.println(ContextPath);
        //3.获取Servlet路径
        String servletPath = req.getServletPath();
        System.out.println(servletPath);
        //4.获取get方式请求参数
        String queryString = req.getQueryString();
        System.out.println(queryString);
        //5.获取请求URL
        StringBuffer requestURL = req.getRequestURL();
        System.out.println(requestURL);
        //6.获取客户机IP地址
        String remoteAddr = req.getRemoteAddr();
        System.out.println(remoteAddr);
        //7.请求协议
        String scheme = req.getScheme();
        System.out.println(scheme);
        //8.获取servletContext
        ServletContext servletContext = req.getServletContext();
        System.out.println(servletContext);
    }
}
